﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControl_Room : Guru.Web.UI.GuruUserControl
{
    #region Constants
    /// <summary>
    /// 0: Room Status, 1 ClientID of Selected Control, 2: RoomID
    /// </summary>
    protected const string JS_SHOW_MENU = "showRoomContextMenu(event, '{0}', '{1}', '{2}');";
    protected const string JS_SELECT = "selectRoom({0},'{1}',this);";   
    #endregion

    #region Properties
    public string RoomName
    {
        set
        {
            uxRoomName.Text = value;
        }
        get
        {
            return uxRoomName.Text;
        }
    }
    public string RoomID
    {
        set 
        { 
            ViewState["RoomID"] = value; 
        }
        get 
        {
            return (string)ViewState["RoomID"]; 
        }
    }
    public string CurrentInvoiceID
    {
        set
        {
            ViewState["CurrentInvoiceID"] = value;
        }
        get
        {
            return (string)ViewState["CurrentInvoiceID"];
        }
    }
    public HSMEnums.RoomStatus Status
    {
        set
        {
            ViewState["Status"] = value;
        }
        get
        {
            if (ViewState["Status"] == null)
                return HSMEnums.RoomStatus.Empty;
            else
                return (HSMEnums.RoomStatus)Enum.Parse(typeof(HSMEnums.RoomStatus), ViewState["Status"].ToString());
        }
    }   
    
    public HSMEnums.SelectionMode SelectionMode
    {
        set
        {
            ViewState["SelectionMode"] = value;
        }
        get
        {
            if (ViewState["SelectionMode"] == null)
                return HSMEnums.SelectionMode.None;
            else
                return (HSMEnums.SelectionMode)Enum.Parse(typeof(HSMEnums.SelectionMode), ViewState["SelectionMode"].ToString());
        }
    }
    public bool Selected
    {
        set 
        {
            this.uxIsSelected.Checked = false;
            this.uxSelectOne.Checked = false;
            this.uxSelectMulti.Checked = false;
            switch (this.SelectionMode)
            {
                case HSMEnums.SelectionMode.None:
                    this.uxIsSelected.Checked = value;
                    break;
                case HSMEnums.SelectionMode.Single:
                    this.uxSelectOne.Checked = value;
                    break;
                case HSMEnums.SelectionMode.Multiple:
                    this.uxSelectMulti.Checked = value;
                    break;
            }
        }
        get 
        {
            switch (this.SelectionMode)
            {
                case HSMEnums.SelectionMode.None:
                    return this.uxIsSelected.Checked;                   
                case HSMEnums.SelectionMode.Single:
                    return this.uxSelectOne.Checked;                   
                case HSMEnums.SelectionMode.Multiple:
                    return this.uxSelectMulti.Checked;
                case HSMEnums.SelectionMode.ContextMenu:
                    return this.uxIsSelected.Checked;
            }
            return false;
        }
    }

    protected string SecurityQueryStringRoomID
    {
        get 
        {
            string invoice = string.IsNullOrEmpty(this.CurrentInvoiceID) ? "0" : this.CurrentInvoiceID;
            return this.Page.BuildSecureQueryString(string.Format("roomID={0}&invoiceID={1}", this.RoomID, invoice));
        }
    }
    #endregion

    #region Page Life Cycle
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        this.ProcessSelectingMode();
        this.ProcessCssStatus();
    }

    protected void ProcessSelectingMode()
    {
        this.uxSelectMulti.Visible = this.uxSelectOne.Visible = false;
        string onRoomClick = string.Empty;
        switch (this.SelectionMode)
        {
            case HSMEnums.SelectionMode.ContextMenu:
                onRoomClick = string.Format(JS_SHOW_MENU, (int)this.Status, this.uxIsSelected.ClientID, this.SecurityQueryStringRoomID);
                break;
            case HSMEnums.SelectionMode.Single:
                onRoomClick = string.Format(JS_SELECT, (int)HSMEnums.SelectionMode.Single, this.uxSelectOne.ClientID);
                this.uxSelectOne.Visible = true;
                break;
            case HSMEnums.SelectionMode.Multiple:
                onRoomClick = string.Format(JS_SELECT, (int)HSMEnums.SelectionMode.Multiple, this.uxSelectMulti.ClientID);
                this.uxSelectMulti.Visible = true;
                break;
        }
        if (!string.IsNullOrEmpty(onRoomClick))
        {
            this.uxRoomInfo.Attributes.Add("onclick", onRoomClick);
        }
    }
    protected void ProcessCssStatus()
    {
        string cssStatus = "room_status_empty";
        switch (this.Status)
        {
            case HSMEnums.RoomStatus.Empty:
               cssStatus = "room_status_empty";
               break;
            case HSMEnums.RoomStatus.Dirty:
               cssStatus = "room_status_dirty";
               break;
            case HSMEnums.RoomStatus.Maintenance:
               cssStatus = "room_status_maintenance";
               break;
            case HSMEnums.RoomStatus.MultiCheckedIn:
               cssStatus = "room_status_checked_in_multi";
               break;
            case HSMEnums.RoomStatus.SingleCheckedIn:
               cssStatus = "room_status_checked_in";
               break;
            case HSMEnums.RoomStatus.Reserved:
               cssStatus = "room_status_reserved";
               break;
        }
        this.uxRoomIcon.Attributes.Add("class", "room_icon " + cssStatus);
    }
    #endregion

    public void BindData()
    { 
    
    }
}
